In [1]:
import cufflinks as cf
Colors can be represented as strings:
HEX "#db4052"
RGB "rgb(219, 64, 82)"
RGBA "rgba(219, 64, 82, 1.0)"
In [2]:
# The colors module includes a pre-defined set of commonly used colors
cf.colors.cnames
Out[2]:
In [3]:
# HEX to RGB
cf.colors.hex_to_rgb('red')
Out[3]:
In [4]:
# RGB to HEX
cf.colors.rgb_to_hex('rgb(219, 64, 82)')
Out[4]:
In [5]:
# RGB or HEX to RGBA (transparency)
cf.colors.to_rgba('#3780bf',.5), cf.colors.to_rgba('rgb(219, 64, 82)',.4)
Out[5]:
In [6]:
# RGBA to RGB (flatten transparency)
# By default assumes that the transparency color is *white*, however this can be also passed as a parameter.
cf.colors.rgba_to_rgb('rgba(219, 64, 82, 0.4)','white')
Out[6]:
In [7]:
# Cufflinks.colors.normalize will always return the an hex value for all types of colors
colors=['#f08','rgb(240, 178, 185)','rgba(219, 64, 82, 0.4)','green']
[cf.colors.normalize(c) for c in colors]
Out[7]:
In [8]:
# 10 different tones of pink
cf.colors.color_range('pink',10)
Out[8]:
In [9]:
# Displaying a table of defined colors (list)
colors=['#f08', 'rgb(240, 178, 185)', 'blue' , '#32ab60']
cf.colors.color_table(colors)
In [10]:
# Generating 15 shades of orange
cf.colors.color_table('orange',15)
In [11]:
# Create a generator using 3 defined base colors
colors=['green','orange','blue']
gen=cf.colors.colorgen(colors)
outputColors=[next(gen) for _ in range(15)]
cf.colors.color_table(outputColors)
In [12]:
# Create a generator with default set of colors
gen=cf.colors.colorgen()
outputColors=[next(gen) for _ in range(15)]
cf.colors.color_table(outputColors)
In [13]:
# We can see all available scales with
cf.get_scales()
Out[13]:
In [14]:
# Other color scales can be also seen here
cf.colors.scales()
In [15]:
colorscale=cf.colors.get_scales('accent')
cf.colors.color_table(colorscale)